import QQMap from '../../../utils/qqmap'
Page({
  data: {
    latitude:28.23529,
    longitude:112.93134,
    repairDetail: {},
    polyline:[],
    markers:[
      {id:1,width:30,height:30, latitude:28.23529,longitude:112.93134},
      {id:2,width:30,height:30, latitude:28.236835,longitude:112.936837,iconPath:'/static/images/marker.png'}
    ]
  },
  onLoad({ id }) {
    this.getRepairDetail(id)
    this.mapline()
  },
  mapline(){
    QQMap.direction({
      mode: 'bicycling',
      from:'28.23529,112.93134',
      to: '28.236835,112.936837', 
      success:({result})=>{
        console.log(result);
       const coors = result.routes[0].polyline
       const points = [];
        //坐标解压（返回的点串坐标，通过前向差分进行压缩）
        const kr = 1000000;
        for (let i = 2; i < coors.length; i++) {
          coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;
        }
        //将解压后的坐标放入点串数组pl中
        for (let i = 0; i < coors.length; i += 2) {
          points.push({ latitude: coors[i], longitude: coors[i + 1] })
        }
        //设置polyline属性，将路线显示出来,将解压坐标第一个数据作为起点
        this.setData({
          latitude:points[0].latitude,
          longitude:points[0].longitude,
          polyline: [{
            points: points,
            color: '#FF0000DD',
            width: 4
          }]
        })
      },
    });
  },
  async getRepairDetail(id) {
    const { code, data: repairDetail } = await wx.http.get('/repair/' + id)
    if (code !== 10000) return wx.utils.toast('获取信息有误')
    this.setData({ repairDetail })
  },
})
